<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="8">
          <el-form-item :label="$t('公司名称')">
            <span v-html="companyName" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('公司简称')">
            <span v-html="companyShortName" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('年份')" prop="nianfen">
            <el-date-picker
              v-model="form.nianfen"
              type="year"
              clearable
              size="small"
              value-format="yyyy"
              placeholder="选择年"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('季度')" prop="jidu">
            <dict-select
              v-model="form.jidu"
              dictionary="report_type"
              :placeholder="$t('季度')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('面积(m²)')" prop="area">
            <Money v-model="form.area" :placeholder="$t('面积')" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('位置')" prop="location">
            <el-input v-model="form.location" :placeholder="$t('位置')" show-word-limit maxlength="200" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('目前员工人数')" prop="upStaffNumber">
            <el-input v-model="form.upStaffNumber" :placeholder="$t('目前员工人数')" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('中级及以上专业技术人员(数量)')" prop="intermediateNumber">
            <el-input v-model="form.intermediateNumber" :placeholder="$t('中级及以上专业技术人员(数量)')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('国家职业资格三级及以上技能人员(数量)')" prop="gjzyzgsjiNumber">
            <el-input v-model="form.gjzyzgsjiNumber" :placeholder="$t('国家职业资格三级及以上技能人员(数量)')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('已有专利总数')" prop="alreadyPatentNumber">
            <el-input v-model="form.alreadyPatentNumber" :placeholder="$t('已有专利总数')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('已有发明专利数量')" prop="alreadyInventionPatentsNumber">
            <el-input v-model="form.alreadyInventionPatentsNumber" :placeholder="$t('已有发明专利数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('已有实用新型专利数量')" prop="alreadyUtilityPatentsNumber">
            <el-input v-model="form.alreadyUtilityPatentsNumber" :placeholder="$t('已有实用新型专利数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('已有外观设计专利数量')" prop="alreadyExteriorNumber">
            <el-input v-model="form.alreadyExteriorNumber" :placeholder="$t('已有外观设计专利数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('已有软著数量')" prop="alreadySoftNumber">
            <el-input v-model="form.alreadySoftNumber" :placeholder="$t('已有软著数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('申请中的专利总数')" prop="applyingPatentNumber">
            <el-input v-model="form.applyingPatentNumber" :placeholder="$t('申请中的专利总数')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('申请中的发明专利数量')" prop="applyingInventionPatentsNumber">
            <el-input v-model="form.applyingInventionPatentsNumber" :placeholder="$t('申请中的发明专利数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('申请中的实用新型专利数量')" prop="applyingUtilityModelNumber">
            <el-input v-model="form.applyingUtilityModelNumber" :placeholder="$t('申请中的实用新型专利数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('申请中的外观设计专利数量')" prop="applyingExteriorNumber">
            <el-input v-model="form.applyingExteriorNumber" :placeholder="$t('申请中的外观设计专利数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('申请中的软著数量')" prop="applyingSoftNumber">
            <el-input v-model="form.applyingSoftNumber" :placeholder="$t('申请中的软著数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('已有一类注册证数量')" prop="alreadyOneEnrollNumber">
            <el-input v-model="form.alreadyOneEnrollNumber" :placeholder="$t('已有一类注册证数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('已有二类注册证数量')" prop="alreadyTwoEnrollNumber">
            <el-input v-model="form.alreadyTwoEnrollNumber" :placeholder="$t('已有二类注册证数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('已有三类注册证数量')" prop="alreadyThreeEnrollNumber">
            <el-input v-model="form.alreadyThreeEnrollNumber" :placeholder="$t('已有三类注册证数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('申报中的一类证数量')" prop="applyingOneEnrollNumber">
            <el-input v-model="form.applyingOneEnrollNumber" :placeholder="$t('申报中的一类证数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('申报中的二类证数量')" prop="applyingTwoEnrollNumber">
            <el-input v-model="form.applyingTwoEnrollNumber" :placeholder="$t('申报中的二类证数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('申报中的三类证数量')" prop="applyingThreeEnrollNumber">
            <el-input v-model="form.applyingThreeEnrollNumber" :placeholder="$t('申报中的三类证数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('处于注册检测阶段的产品数量')" prop="inEnrollNumber">
            <el-input v-model="form.inEnrollNumber" :placeholder="$t('处于注册检测阶段的产品数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('处于临床阶段的产品数量')" prop="inClinicNumber">
            <el-input v-model="form.inClinicNumber" :placeholder="$t('处于临床阶段的产品数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('处于评审阶段的产品数量')" prop="inReviewNumber">
            <el-input v-model="form.inReviewNumber" :placeholder="$t('处于评审阶段的产品数量')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('当季度研发开发费用合计') + $t('金额单位')" prop="inSeasonYffyhj">
            <Money v-model="form.inSeasonYffyhj" unit="w" :placeholder="$t('当季度研发开发费用合计')" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('当季度工业总产值') + $t('金额单位')" prop="inSeasonGyzcz">
            <Money v-model="form.inSeasonGyzcz" unit="w" :placeholder="$t('当季度工业总产值')" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('当季度营业收入') + $t('金额单位')" prop="inSeasonYesr">
            <Money v-model="form.inSeasonYesr" unit="w" :placeholder="$t('当季度营业收入')" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('当季度应交增值税') + $t('金额单位')" prop="inSeasonYjzzs">
            <Money v-model="form.inSeasonYjzzs" unit="w" :placeholder="$t('当季度应交增值税')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('企业目前存在的困难')" prop="presentDifficulty">
            <el-input v-model="form.presentDifficulty" type="textarea" :placeholder="$t('企业目前存在的困难')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('目前项目进展情况')" prop="currentProjectProgress">
            <el-input v-model="form.currentProjectProgress" type="textarea" :placeholder="$t('目前项目进展情况')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('下一步计划（未投产的企业需列出预计具体投产时间）')" prop="nextPlan">
            <el-input v-model="form.nextPlan" type="textarea" :placeholder="$t('下一步计划（未投产的企业需列出预计具体投产时间）')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('目前办证情况（注册证）：一、正在申报的注册证名称及其所属类别，申报进度（申报进度需写明目前走到哪个注册阶段，例如临床或型检等）')" prop="certificationOne">
            <el-input v-model="form.certificationOne" type="textarea" :placeholder="$t('目前办证情况（注册证）：一、正在申报的注册证名称及其所属类别，申报进度（申报进度需写明目前走到哪个注册阶段，例如临床或型检等）')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('目前办证情况（注册证）：二、') + $t(year) + ('年能拿到的注册证名称、类别')" prop="certificationTwo">
            <el-input v-model="form.certificationTwo" type="textarea" :placeholder="$t('目前办证情况（注册证）：二、') + $t(year) + ('年能拿到的注册证名称、类别')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('目前办证情况（注册证）：三、') + $t(year) + ('年已拿到的注册证名称及其所属类别，需全部列出')" prop="certificationThree">
            <el-input v-model="form.certificationThree" type="textarea" :placeholder="$t('目前办证情况（注册证）：三、') + $t(year) + ('年已拿到的注册证名称及其所属类别，需全部列出')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('人才情况（硕士、博士、500精英计划等，填写人才姓名、其所属类别、获评时间）')" prop="talentSituation">
            <el-input v-model="form.talentSituation" type="textarea" :placeholder="$t('人才情况（硕士、博士、500精英计划等，填写人才姓名、其所属类别、获评时间）')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('企业荣誉情况（获得时间、荣誉名称、荣誉类型）（如获评高新技术企业、科中小企业、专精特新小巨人、首台套、大赛获奖等荣誉）')" prop="corporateHonors">
            <el-input v-model="form.corporateHonors" type="textarea" :placeholder="$t('企业荣誉情况（获得时间、荣誉名称、荣誉类型）（如获评高新技术企业、科中小企业、专精特新小巨人、首台套、大赛获奖等荣誉）')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('用工需求（用工需求类型、人数）')" prop="employmentNeeds">
            <el-input v-model="form.employmentNeeds" type="textarea" :placeholder="$t('用工需求（用工需求类型、人数）')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('用地需求（详细写明需求年份、面积和形式）')" prop="landUseRequirements">
            <el-input v-model="form.landUseRequirements" type="textarea" :placeholder="$t('用地需求（详细写明需求年份、面积和形式）')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('是否有出口计划（大概额度，写明货币种类）')" prop="isExportPlan">
            <el-input v-model="form.isExportPlan" type="textarea" :placeholder="$t('是否有出口计划（大概额度，写明货币种类）')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="deal:implementation" />
    </div>
  </div>
</template>

<script>
    import { saveCompanyImplementation, getCompanyImplementation } from '@/api/sass/lanwan/companyImplementation'
    import { getCompanyBase } from '@/api/company/base/companyBase'
    export default {
        data() {
          const numberAstrict = (rule, value, callback) => {
            if (value !== undefined && value !== '' && value !== null) {
                var regNumber = /^[0-9]*[0-9][0-9]*$/
                if (!regNumber.test(value)) {
                  callback(new Error(this.$t('只能录入正整数')))
                }
                if (value.length > 10 || value > 2147483647) {
                  callback(new Error(this.$t('数量过大')))
                }
            }
            callback()
          }
            return {
                // 表单参数
                form: {},
                // 当前年
                year: new Date().getFullYear().toString(),
                // 公司名称
                companyName: undefined,
                // 公司简称
                companyShortName: undefined,
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                nianfen: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                jidu: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                  currentProjectProgress: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  nextPlan: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  certificationOne: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  certificationTwo: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  certificationThree: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  talentSituation: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  corporateHonors: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  employmentNeeds: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  landUseRequirements: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  isExportPlan: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  upStaffNumber: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' },
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  intermediateNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  gjzyzgsjiNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  alreadyPatentNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  alreadyInventionPatentsNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  alreadyUtilityPatentsNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  alreadyExteriorNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  alreadySoftNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  applyingPatentNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  applyingInventionPatentsNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  applyingExteriorNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  applyingSoftNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  alreadyOneEnrollNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  alreadyTwoEnrollNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  alreadyThreeEnrollNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  applyingOneEnrollNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  applyingTwoEnrollNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  applyingThreeEnrollNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  inEnrollNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  inClinicNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  inReviewNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ],
                  applyingUtilityModelNumber: [
                    { validator: numberAstrict, trigger: 'blur' }
                  ]
                }
            }
        },
        created() {
            this.getDicts('report_type').then(response => {
                this.jiduOptions = response.data
            })
          // 获取公司名称和简称
          getCompanyBase(this.$route.query.companyId).then(response => {
            this.companyName = response.data.companyName
            this.companyShortName = response.data.companyShortName
          })
        },
        methods: {
            // 初始化数据
            init(data) {
                this.loading = true
                if (data != null && data.id !== undefined) {
                    getCompanyImplementation(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    }).catch(() => {
                      this.loading = false
                    })
                } else {
                    this.reset()
                    this.gainYear()
                    this.loading = false
                }
            },
          // 获取当前年份和当前季度
          gainYear() {
            const myDate = new Date()
            var month = myDate.getMonth() + 1
            if (month >= 1 && month <= 3) {
              this.form.jidu = '1'
            } else if (month >= 4 && month <= 6) {
              this.form.jidu = '2'
            } else if (month >= 7 && month <= 9) {
              this.form.jidu = '3'
            } else {
              this.form.jidu = '4'
            }
            this.form.nianfen = myDate.getFullYear().toString()
          },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                  dealId: this.$route.query.id,
                  companyId: this.$route.query.companyId,
                    reportName: undefined,
                    nianfen: undefined,
                    jidu: undefined,
                    area: undefined,
                    location: undefined,
                    upStaffNumber: undefined,
                    intermediateNumber: undefined,
                    gjzyzgsjiNumber: undefined,
                    alreadyPatentNumber: undefined,
                    alreadyInventionPatentsNumber: undefined,
                    alreadyUtilityPatentsNumber: undefined,
                    alreadyExteriorNumber: undefined,
                    alreadySoftNumber: undefined,
                    applyingPatentNumber: undefined,
                    applyingInventionPatentsNumber: undefined,
                    applyingExteriorNumber: undefined,
                    applyingSoftNumber: undefined,
                    alreadyOneEnrollNumber: undefined,
                    alreadyTwoEnrollNumber: undefined,
                    alreadyThreeEnrollNumber: undefined,
                    applyingOneEnrollNumber: undefined,
                    applyingTwoEnrollNumber: undefined,
                    applyingThreeEnrollNumber: undefined,
                    inEnrollNumber: undefined,
                    inClinicNumber: undefined,
                    inReviewNumber: undefined,
                    presentDifficulty: undefined,
                    currentProjectProgress: undefined,
                    nextPlan: undefined,
                    certificationOne: undefined,
                    certificationTwo: undefined,
                    certificationThree: undefined,
                    talentSituation: undefined,
                    corporateHonors: undefined,
                    employmentNeeds: undefined,
                    landUseRequirements: undefined,
                    isExportPlan: undefined,
                  inSeasonYffyhj: undefined,
                  inSeasonGyzcz: undefined,
                  inSeasonYesr: undefined,
                  inSeasonYjzzs: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveCompanyImplementation(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                }).catch(() => {
                    this.loading = false
                })
           }
        }
    }
</script>
